#编写beautifulsoup爬虫，获取猫眼电影网站的top100电影名

import requests
from bs4 import BeautifulSoup

cookies = {
    'uuid_n_v': 'v1',
    'iuuid': '1517C660BCEF11EF8CC993F69A204439D09651F9E9174232B261AC6CC3AC9962',
    'Hm_lvt_e0bacf12e04a7bd88ddbd9c74ef2b533': '1734492052',
    'HMACCOUNT': 'B2C21EEE3F1F23B1',
    '_lxsdk_cuid': '193d7c85914c8-067df6ac552017-26011851-144000-193d7c85914c8',
    '_lxsdk_s': '193d7c85915-0d8-b11-a39%7C%7CNaN',
    '_lxsdk': '1517C660BCEF11EF8CC993F69A204439D09651F9E9174232B261AC6CC3AC9962',
    '_ga': 'GA1.1.1747353465.1734492052',
    '_ga_WN80P4PSY7': 'GS1.1.1734492051.1.1.1734492127.0.0.0',
    'Hm_lpvt_e0bacf12e04a7bd88ddbd9c74ef2b533': '1734492128',
}

headers = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Cache-Control': 'max-age=0',
    'Connection': 'keep-alive',
    # 'Cookie': 'uuid_n_v=v1; iuuid=1517C660BCEF11EF8CC993F69A204439D09651F9E9174232B261AC6CC3AC9962; Hm_lvt_e0bacf12e04a7bd88ddbd9c74ef2b533=1734492052; HMACCOUNT=B2C21EEE3F1F23B1; _lxsdk_cuid=193d7c85914c8-067df6ac552017-26011851-144000-193d7c85914c8; _lxsdk_s=193d7c85915-0d8-b11-a39%7C%7CNaN; _lxsdk=1517C660BCEF11EF8CC993F69A204439D09651F9E9174232B261AC6CC3AC9962; _ga=GA1.1.1747353465.1734492052; _ga_WN80P4PSY7=GS1.1.1734492051.1.1.1734492127.0.0.0; Hm_lpvt_e0bacf12e04a7bd88ddbd9c74ef2b533=1734492128',
    'Sec-Fetch-Dest': 'document',
    'Sec-Fetch-Mode': 'navigate',
    'Sec-Fetch-Site': 'none',
    'Sec-Fetch-User': '?1',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
    'sec-ch-ua': '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}



if __name__ == '__main__':
    response = requests.get('https://m.maoyan.com/asgard/board/4', cookies=cookies, headers=headers)
    #用beautifulsoup解析
    soup = BeautifulSoup(response.text, 'html.parser')
    data = soup.find_all('div', class_='info')
    print(data)
    for i in data:
        with open('maoyan_movie_name.txt', 'a', encoding='utf-8') as f:
            f.write(i.find('h3').text + '\n')
    f.close()


    # <h3 class="title">我不是药神</h3>   按照这个标签来
    # h3 = str(h3)
    # print(type(h3))
    # movie_name = re.findall('[\u4e00-\u9fa5]+', h3, re.S)
    # for i in movie_name:
    #     with open('movie_name.txt', 'a', encoding='utf-8') as f:
    #         f.write(i + '\n')
    # f.close()
    # print(movie_name)